package com.zkca.xf.ui.activity.me;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.zkca.xf.R;
import com.zkca.xf.base.BaseTitleActivity;
import com.zkca.xf.utils.CleanMessageUtil;

import java.io.File;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends BaseTitleActivity {
    @BindView(R.id.tv_cache)
    TextView tv_cache;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_setting);
        ButterKnife.bind(this);
        setTitleText("设置");
        setleftTextVisibility(true);
        setleftImgVisibility(true);

        initData();
    }

    private void initData() {
//        String sdPath = Environment.getExternalStorageDirectory().getAbsolutePath();
        File outCachePath = SettingActivity.this.getExternalCacheDir();
//        outFilePath = SettingActivity.this.getExternalFilesDir(Environment.DIRECTORY_ALARMS);
        try {
            String outCacheSize = CleanMessageUtil.getCacheSize(outCachePath);
//            String outFileSize = CleanMessageUtil.getCacheSize(outFilePath);
            tv_cache.setText(outCacheSize);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @OnClick({R.id.ll_versions, R.id.ip_port, R.id.ll_help, R.id.ll_cache, R.id.ll_paw})
    public void onClick(View view) {
        Intent intent = new Intent();
        switch (view.getId()) {
            case R.id.ll_versions://版本信息
                intent.setClass(SettingActivity.this, VersionsActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_help://帮助
                intent.setClass(SettingActivity.this, HelpActivity.class);
                startActivity(intent);
                break;
            case R.id.ll_cache://清除缓存
                AlertDialog.Builder normalDialog =
                        new AlertDialog.Builder(SettingActivity.this);
                normalDialog.setMessage("请问您是否清除缓存");
                normalDialog.setPositiveButton("确定",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                CleanMessageUtil.cleanExternalCache(SettingActivity.this);
                                tv_cache.setText("0.00B");
                                dialog.dismiss();
                            }
                        });
                normalDialog.setNegativeButton("取消",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.dismiss();
                            }
                        });
                // 显示
                normalDialog.show();
                break;
            case R.id.ll_paw://修改密码
                intent.setClass(SettingActivity.this, ChangeQasswordActivity.class);
                startActivity(intent);
                break;
            case R.id.ip_port:
                intent.setClass(SettingActivity.this, IP_PortActivity.class);
                startActivity(intent);
                finish();
                break;
        }
    }


}
